package com.zking.frame.dhy;

import java.awt.BorderLayout;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import com.zking.db.BaseDao;
import com.zking.entityClass.BookInfo;

public class BookSearch extends JDialog implements TreeSelectionListener {

	{
		// 调用美化包
		BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
		try {
			org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

//北部
	private JPanel jp_north;
	private JButton jb_query;// 查询
	private JTextField tf_query;// 查询文本框
	private JLabel null_jl;// 空的
	private JButton jb_seniorQuery;// 高级查询

//中部
	private JPanel jp_center;
	// 中部的西部
	private JPanel jp_center_west;
	private JLabel jl_booknumber;// 书号
	private JTextField jtx_booknumber;// 书号文本框
	private JLabel jl_bookname;// 书名
	private JTextField jtx_bookname;
	private JLabel jl_bookType;// 书的类型
	private JComboBox<String> jcb_bookType;
	private JLabel jl_author;// 作者
	private JTextField jtx_author;
	private JLabel jl_press;// 出版社
	private JTextField jtx_press;
	private JLabel jl_bookcount;// 书的数量
	private JTextField jtx_bookcount;
	private JLabel jl_costPrice;// 成本价
	private JTextField jtx_costPrice;
	private JLabel jl_price;// 定价
	private JTextField jtx_price;
	private JLabel jl_retailPrice;// 零售价
	private JTextField jtx_retailPrice;
	private JLabel jl_wholesale;// 批发价
	private JTextField jtx_wholesale;
	public List<BookInfo> booklist = new ArrayList<BookInfo>();
	// 中部的东部
	private JPanel jp_center_east;
	private JButton jb_seniorQuery_query;// 查询按钮
	private JButton jb_return;// 隐藏按钮

//南部

	private JPanel jp_south;
//将中部面板分割  分为左和右
	private JSplitPane jsplitPane;
	private JPanel jp_south_left;// 左边
	private JPanel jp_south_right;// 右边
//左边为树状列表
	private JTree tree;
//右边
	private DefaultTableModel contentArea;
	private JTable table;
	private String[][] data;
	private String[] header = new String[] { "书号", "书名", "出版社", "作者", "库存数量", "定价", "零售价", "零售折扣", "批发价", "成本价",
			"书的类型" };
//边框
	private Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
	
	private int selectRow;
	private String bookid;
//图片
	private ImageIcon img_query = new ImageIcon(BooksData.class.getResource("11.png"));
	private ImageIcon img_seniorQuery = new ImageIcon(BooksData.class.getResource("高级查询.png"));
	private ImageIcon img_return = new ImageIcon(BooksData.class.getResource("隐藏.png"));

	BaseDao base = new BaseDao();

	public BookSearch(boolean flag,final DaySave daySave,boolean flag2) {

		setLayout(new FlowLayout());

		// 北部
		jp_north = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 5));
		jp_north.setPreferredSize(new Dimension(1024, 50));

		// 创建三个按钮
		JRadioButton jrb1 = new JRadioButton("所以商品");
		jrb1.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				JRadioButton checkBox = (JRadioButton) e.getSource();
				if (checkBox.isSelected() == true) {
					contentArea.setDataVector(null, header);
					allsql();
				}
				
				
			}
		});
		JRadioButton jrb2 = new JRadioButton("库存大于0",true);
		jrb2.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
                String sql = "select * from bookinfo where inventoryNums>0";
                JRadioButton checkBox = (JRadioButton) e.getSource();
				if (checkBox.isSelected() == true) {
					contentArea.setDataVector(null, header);
					 needNature(sql);
				}
			}
		});
		JRadioButton jrb3 = new JRadioButton("库存等于0");
		jrb3.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
                String sql = "select * from bookinfo where inventoryNums=0";
                JRadioButton checkBox = (JRadioButton) e.getSource();
				if (checkBox.isSelected() == true) {
					contentArea.setDataVector(null, header);
					 needNature(sql);
				}
			}
		});
		// 将三个按钮分成一个组
		ButtonGroup bg = new ButtonGroup();
		// 再将三个按钮加入到组中
		bg.add(jrb1);
		bg.add(jrb2);
		bg.add(jrb3);
		if (flag2 == true) {
			// 将三个按钮加入到面板中
			jp_north.add(jrb1);
			jp_north.add(jrb2);
			jp_north.add(jrb3);
		}else {
			jp_north.add(jrb2);
		}
		// 查询按钮
		jb_query = new JButton(img_query);
		jb_query.setBorder(border);
		jb_query.setFont(new Font("楷体", Font.BOLD, 20));
		jb_query.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				if (tf_query.getText().equals("") || tf_query.getText().length() == 0) {
					JOptionPane.showMessageDialog(BookSearch.this, "填写搜索关键词", "error", JOptionPane.ERROR_MESSAGE);
					return;
				}
				String sql1 = "select * from bookinfo where type = ?";
				String sql2 = "select * from bookinfo where bookname = ?";
				List<Object> params = new ArrayList<>();
				List<Object[]> data = null;
				params.add(tf_query.getText());
				boolean flag1 = true;
				boolean flag2 = true;
				
				try {
					data = base.queryArrayListHandler(sql1, params.toArray());
					if (data.size() == 0) {
						flag1 = false;
						data = base.queryArrayListHandler(sql2, params.toArray());
						if (data.size() == 0) {
							flag2 = false;
							JOptionPane.showMessageDialog(BookSearch.this, "没有此类书籍", "提示", JOptionPane.ERROR_MESSAGE);
							return;
						} 
					}
					if (flag1 == true) {
						contentArea.setDataVector(null, header);// 清空面板
						needNature(sql1, params.toArray());
					}else if (flag2 == true && flag1 == false) {
						contentArea.setDataVector(null, header);// 清空面板
						needNature(sql2, params.toArray());
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

//				
//				for(int i=0;data!=null&&i<data.size();i++) {
//				  contentArea.addRow(data.get(i));
//				
//			}

			}
		});
		// jb_query.setBorder(border);
		// 查询文本框
		tf_query = new JTextField("输入书名或者类型");
		tf_query.setPreferredSize(new Dimension(150, 30));
		tf_query.addMouseListener(new MouseListener() {
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				tf_query.setText("");
			}

			public void mousePressed(MouseEvent e) {
			}

			public void mouseExited(MouseEvent e) {
			}

			public void mouseEntered(MouseEvent e) {
			}

			public void mouseClicked(MouseEvent e) {
			}
		});

		// 空的组件
		null_jl = new JLabel("        " + "          " + "     ");
		// 高级查询
		jb_seniorQuery = new JButton(img_seniorQuery);
		jb_seniorQuery.setBorder(border);
		jb_seniorQuery.setFont(new Font("楷体", Font.BOLD, 20));
		jb_seniorQuery.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
				jp_center.setVisible(true);
				new BookSearch(true,daySave,true);

			}
		});

		jp_north.add(tf_query);
		jp_north.add(jb_query);
		jp_north.add(null_jl);
		jp_north.add(jb_seniorQuery);

		// 中部
		jp_center = new JPanel(new BorderLayout());
		jp_center.setPreferredSize(new Dimension(1000, 100));

		// 1.1西部
		jp_center_west = new JPanel(new GridLayout(3, 6, 5, 5));
		jl_booknumber = new JLabel("书号:");
		jl_booknumber.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_booknumber = new JTextField();
		jtx_booknumber.setFont(new Font("楷体", Font.BOLD, 20));

		jl_bookname = new JLabel("书名:");
		jl_bookname.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_bookname = new JTextField();
		jtx_bookname.setFont(new Font("楷体", Font.BOLD, 20));

		jl_bookType = new JLabel("类型:");
		jl_bookType.setFont(new Font("楷体", Font.BOLD, 20));

		jcb_bookType = new JComboBox<String>();
		String[] test = { "教辅", "文学", "地理", "考试", "历史", "音乐", "其他书籍" };
		for (int i = 0; i < test.length; i++) {
			jcb_bookType.addItem(test[i]);
		}
		jcb_bookType.setFont(new Font("楷体", Font.BOLD, 20));

		jl_author = new JLabel("作者:");
		jl_author.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_author = new JTextField();
		jtx_author.setFont(new Font("楷体", Font.BOLD, 20));

		jl_costPrice = new JLabel("成本价:");
		jl_costPrice.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_costPrice = new JTextField();
		jtx_costPrice.setFont(new Font("楷体", Font.BOLD, 20));

		jl_price = new JLabel("定价:");
		jl_price.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_price = new JTextField();
		jtx_price.setFont(new Font("楷体", Font.BOLD, 20));

		jl_retailPrice = new JLabel("零售价:");
		jl_retailPrice.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_retailPrice = new JTextField();
		jtx_retailPrice.setFont(new Font("楷体", Font.BOLD, 20));

		jl_wholesale = new JLabel("批发价:");
		jl_wholesale.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_wholesale = new JTextField();
		jtx_wholesale.setFont(new Font("楷体", Font.BOLD, 20));

		jtx_booknumber.setPreferredSize(new Dimension(100, 30));
		jtx_bookname.setPreferredSize(new Dimension(100, 30));
		jtx_author.setPreferredSize(new Dimension(100, 30));
		jtx_costPrice.setPreferredSize(new Dimension(100, 30));
		jtx_price.setPreferredSize(new Dimension(100, 30));
		jtx_retailPrice.setPreferredSize(new Dimension(100, 30));
		jtx_wholesale.setPreferredSize(new Dimension(100, 30));

		jp_center_west.add(jl_booknumber);
		jp_center_west.add(jtx_booknumber);
		jp_center_west.add(jl_bookname);
		jp_center_west.add(jtx_bookname);
		jp_center_west.add(jl_bookType);
		jp_center_west.add(jcb_bookType);
		jp_center_west.add(jl_author);
		jp_center_west.add(jtx_author);
		jp_center_west.add(jl_costPrice);
		jp_center_west.add(jtx_costPrice);
		jp_center_west.add(jl_price);
		jp_center_west.add(jtx_price);
		jp_center_west.add(jl_retailPrice);
		jp_center_west.add(jtx_retailPrice);
		jp_center_west.add(jl_wholesale);
		jp_center_west.add(jtx_wholesale);

		// 1.2东部
		jp_center_east = new JPanel(new GridLayout(2, 1, 40, 40));
		jb_seniorQuery_query = new JButton(img_query);// 查询
		jb_seniorQuery_query.setBorder(border);
		jb_seniorQuery_query.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				contentArea.setDataVector(null, header);
				String sql = "select * from bookinfo where ";
				List<Object> params = new ArrayList<>();

				boolean flags = false;// is frist
				// boolean flag = true;// is add and

				if (!(jtx_booknumber.getText().equals("") || jtx_booknumber.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "id = ?";
					params.add(jtx_booknumber.getText());
				}
				if (!(jtx_bookname.getText().equals("") || jtx_bookname.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "bookname = ?";
					params.add(jtx_bookname.getText());
				}
				if (!(jcb_bookType.getSelectedItem().equals(""))) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "type = ?";
					params.add(jcb_bookType.getSelectedItem());
				}
				if (!(jtx_author.getText().equals("") || jtx_author.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "author = ?";
					params.add(jtx_author.getText());
				}
				if (!(jtx_costPrice.getText().equals("") || jtx_costPrice.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "costPrice = ?";
					params.add(jtx_costPrice.getText());
				}
				if (!(jtx_price.getText().equals("") || jtx_price.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "price = ?";
					params.add(jtx_price.getText());
				}
				if (!(jtx_retailPrice.getText().equals("") || jtx_retailPrice.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "retailPrice = ?";
					params.add(jtx_retailPrice.getText());
				}

				if (!(jtx_wholesale.getText().equals("") || jtx_wholesale.getText().length() == 0)) {
					if (flags == false) {
						flags = true;
					} else if (flags = true) {
						sql += " and ";
					}
					sql += "wholsalePrice = ?";
					params.add(jtx_wholesale.getText());
				}

				try {
					List<Object[]> data=base.queryArrayListHandler(sql,params.toArray());
					if (data.size() == 0) {
						JOptionPane.showMessageDialog(BookSearch.this, "没有此类书籍", "提示", JOptionPane.ERROR_MESSAGE);
						return;
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			    needNature(sql, params.toArray());
			   

				
			}
		});

		jb_return = new JButton(img_return);// 隐藏
		jb_return.setBorder(border);
		jb_return.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				jp_center.setVisible(false);

			}
		});

		jp_center_east.add(jb_seniorQuery_query);
		jp_center_east.add(jb_return);

		// 1.3将两个面板放入中部
		jp_center.add(BorderLayout.WEST, jp_center_west);
		jp_center.add(BorderLayout.EAST, jp_center_east);

		// 南部
		jp_south = new JPanel(new BorderLayout());
		if (flag == true) {
			jp_south.setPreferredSize(new Dimension(1024, 650));
		} else {

			jp_south.setPreferredSize(new Dimension(1024, 700));
		}
		// 1.1分割面板
		jsplitPane = new JSplitPane();
		jp_south_left = new JPanel(new BorderLayout());
		jp_south_right = new JPanel(new BorderLayout());
		jsplitPane.setLeftComponent(jp_south_left);
		jsplitPane.setRightComponent(jp_south_right);
		// 分隔条上显示快速 折叠/展开 两边组件的小按钮
		jsplitPane.setOneTouchExpandable(true);
		// 拖动分隔条时连续重绘组件
		jsplitPane.setContinuousLayout(true);
		// 设置分隔条的初始位置
		jsplitPane.setDividerLocation(150);

		// 1.2左边面板
		// 创建根节点
		DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("所有类别");

		// 二级节点
		DefaultMutableTreeNode gdNode = new DefaultMutableTreeNode("书籍类");
		DefaultMutableTreeNode fjNode = new DefaultMutableTreeNode("其他");

		// 把二级节点作为子节点添加到根节点
		rootNode.add(gdNode);
		rootNode.add(fjNode);

		// 创建三级节点
		DefaultMutableTreeNode gzNode = new DefaultMutableTreeNode("教辅");
		DefaultMutableTreeNode szNode = new DefaultMutableTreeNode("文学");

		DefaultMutableTreeNode fzNode = new DefaultMutableTreeNode("地理");
		DefaultMutableTreeNode xmNode = new DefaultMutableTreeNode("考试");

		DefaultMutableTreeNode tbNode = new DefaultMutableTreeNode("历史");
		DefaultMutableTreeNode gxNode = new DefaultMutableTreeNode("音乐");
		DefaultMutableTreeNode jlNode = new DefaultMutableTreeNode("其他书籍");

		// 把三级节点作为子节点添加到相应的二级节点
		gdNode.add(gzNode);
		gdNode.add(szNode);

		gdNode.add(fzNode);
		gdNode.add(xmNode);

		gdNode.add(tbNode);
		gdNode.add(gxNode);
		fjNode.add(jlNode);

		// 用实现了TreeModel接口的DefaultTreeModel类来指定树的根结点
		DefaultTreeModel dtm = new DefaultTreeModel(rootNode);
		// 用这个根结点就可以去建立JTree树了
		tree = new JTree(dtm);
		tree.addTreeSelectionListener(this);// 为这棵树注册监听器

		// 设置树显示根节点句柄
		tree.setShowsRootHandles(true);

		// 设置树节点可编辑
		tree.setEditable(false);

		// 创建滚动面板，包裹树（因为树节点展开后可能需要很大的空间来显示，所以需要用一个滚动面板来包裹）
		JScrollPane scrollPane = new JScrollPane(tree);

		// 添加滚动面板到那内容面板
		jp_south_left.add(scrollPane, BorderLayout.CENTER);

		tree.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				// 如果在这棵树上点击了2次,即双击
				if (e.getSource() == tree && e.getClickCount() == 2) {
					// 按照鼠标点击的坐标点获取路径
					TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
					if (selPath != null)// 谨防空指针异常!双击空白处是会这样
					{
						// 获取这个路径上的最后一个组件,也就是双击的地方
						DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent();
						if (node.toString() == "所有类别") {
							allsql();
						}
					}
				}

			}

		});

		// 1.3右边面板
		// 表格
		contentArea = new DefaultTableModel(header, 0);

		table = new JTable(contentArea);
		//table.setEnabled(false);
		
		JScrollPane sp_center_right = new JScrollPane(table);
		JTableHeader head = table.getTableHeader();
		head.setPreferredSize(new Dimension(head.getWidth(), 35));
		head.setFont(new Font("楷体", Font.BOLD, 15));
		table.setFont(new Font("宋体", Font.PLAIN, 17));
		table.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
			
					try {
						selectRow = table.getSelectedRow();
						String id =  table.getModel().getValueAt(selectRow, 0).toString();
						daySave.jtx_input.setText(id);
						dispose();
						
					} catch (Exception e2) {
						// TODO: handle exception
					}
			
				}   
			
		});

		sp_center_right.getViewport().setOpaque(false);
		sp_center_right.setBackground(Color.white);

		jp_south_right.add(sp_center_right);
		jp_south.add(jsplitPane);

		String sql = "select * from bookinfo where inventoryNums>0";
	    needNature(sql);

		add(BorderLayout.NORTH, jp_north);
		add(BorderLayout.CENTER, jp_center);
		add(BorderLayout.CENTER, jp_south);
		if (flag == true) {
			jp_center.setVisible(true);
		} else {

			jp_center.setVisible(false);
		}
		setTitle("图书查询");
		setSize(1025, 685);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		setLocationRelativeTo(this);
		setVisible(true);

	}

	// 将int型转为string型
	public String doubleFormat(double number, String pattern) {
		DecimalFormat df = new DecimalFormat();
		df.applyPattern(pattern);
		return df.format(number);
	}
	
	


	// 获取高级查询中的消息
	public String[] getMemberInfoData() {
		try {

			String booknumber = jtx_booknumber.getText();
			if (jtx_booknumber.getText() == "" || booknumber.length() == 0) {
				booknumber = null;
			}
			String bookname = jtx_bookname.getText();//
			String press = jtx_press.getText();//
			String author = jtx_author.getText();
			String bookType = (String) jcb_bookType.getSelectedItem();
			String bookcount = doubleFormat(Double.parseDouble(jtx_bookcount.getText()), "000");
			String price = doubleFormat(Double.parseDouble(jtx_price.getText()), "00.0");
			String retailPrice = doubleFormat(Double.parseDouble(jtx_retailPrice.getText()), "00.0");
			String costPrice = doubleFormat(Double.parseDouble(jtx_costPrice.getText()), "00.0");
			String wholesale = doubleFormat(Double.parseDouble(jtx_wholesale.getText()), "00.0");

			String[] rowData = { booknumber, bookname, press, author, bookcount, price, retailPrice, costPrice,
					wholesale, bookType };
			return rowData;

		} catch (Exception e) {

		}
		return null;
	}

	public static void main(String[] args) {

		
		new BookSearch(false, null,true);
	}

	// 将所有数据加入面板中
	
	public void allsql() {
		contentArea.setDataVector(null, header);// 清空面板
		String sqlall = "SELECT * FROM bookinfo";
		needNature(sqlall);
	}
	// 取出相应的字段
	public void needNature(String sql,Object...params) {
		try {
			booklist = base.findList(BookInfo.class, sql,params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		for (int i = 0; booklist != null && i < booklist.size(); i++) {
			BookInfo books = booklist.get(i);
			Vector<Object> rowData = new Vector<>();
			rowData.add(books.getId());
			rowData.add(books.getBookName());
			rowData.add(books.getPublishHouse());
			rowData.add(books.getAuthor());
			rowData.add(books.getInventoryNums());
			rowData.add(books.getPrice());
			rowData.add(books.getRetailPrice());
			rowData.add(10*(books.getRetailDiscount()/books.getRetailPrice()));
			rowData.add(books.getWholsalePrice());
			rowData.add(books.getCostPrice());
			rowData.add(books.getType());
			contentArea.addRow(rowData);
		}

	}

	// 根据类别选择语句
	public void typeSql(String str) {
		String sql = "SELECT * FROM bookinfo WHERE TYPE = ?";
			contentArea.setDataVector(null, header);
			List<Object> params = new ArrayList<>();
			params.add(str);
			needNature(sql,params.toArray());
	}

	@Override
	public void valueChanged(TreeSelectionEvent e) {
		if (e.getSource() == tree) // 如果是要相应的那棵树
		{
			// 获取当前选择的第一个结点中的最后一个路径组件
			DefaultMutableTreeNode dmt = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
			// 如果是叶子结点
			if (dmt.isLeaf()) {
				String str = dmt.toString();// 叶子结点的字符串
				// 判断
				if (str.equals("教辅")) {
					typeSql(str);
				} else if (str.equals("文学")) {
					typeSql(str);
				} else if (str.equals("地理")) {
					typeSql(str);
				} else if (str.equals("考试")) {
					typeSql(str);
				} else if (str.equals("历史")) {
					typeSql(str);
				} else if (str.equals("音乐")) {
					typeSql(str);
				} else {
					typeSql("其他书籍");
				}
			}

		}

	}

}
